package com.janj.bean;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

//测试类:查询所有
public class Test1 {
    public static void main(String[] args) throws Exception {
        //1.加载配置文件 MyBatisConfig.xml
        InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");

        //2.准备工厂
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);

        //3.获取对象
        SqlSession session = factory.openSession();

        //4.执行sql,执行 StudentMapper.xml
        List<Student> array = session.selectList("StudentMapper.selectAll");

        //5.处理结果
        for (Student stu : array) {
            System.out.println(stu);
        }
        //6.释放资源
        is.close();
        session.close();

    }
}
